<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<fieldset>
    <legend>用户注册</legend>
    <form>
    <input id="name" onblur="checkname()">
        <button type="button">注册</button>
    </form>
    <span id="result"></span>
</fieldset>

</body>
<script>
    function checkname(){
        debugger;
        let xhr=new XMLHttpRequest();
        xhr.onreadystatechange=function (){
            if (xhr.readyState==4&&xhr.status==200){
                document.getElementById("result").innerHTML=xhr.responseText;
            }
        }
        var name=document.getElementById("name").value;
        xhr.open("GET","http://localhost:8080/checkName?name="+name,true)
        xhr.send(null);
    }
</script>
</html>